import axios from 'axios';
import { baseURL } from './index';
const instance = axios.create({
    instance,
    timeout: 20000,
    withCredentials: false,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
    },
});
instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
instance.defaults.baseURL=baseURL
// 请求拦截器
instance.interceptors.request.use(
    (config = {}) => {
        console.log("config is",config)
        return config;
    },
    error => Promise.error(error));
// 返回状态判断(添加响应拦截器)
instance.interceptors.response.use(
    res => {
        if (res.data) {
            return new Promise((resolve) => {
                const response = res.data;
                resolve(response&&JSON.parse(response))
            })
        } else {
            return Promise.reject('请求异常')
        }
    },
    error => {
        if (error.message) {
            return Promise.reject(error.message)
        }
        // 返回 response 里的错误信息
        const errorInfo = error.data.error ? error.data.error.message : error.data
        return Promise.reject(errorInfo)
    }
)
export default instance;